package com.tianji.learning.controller;


import com.tianji.api.dto.leanring.LearningLessonDTO;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domin.dto.LearningPlanDTO;
import com.tianji.learning.domin.vo.LearningLessonVO;
import com.tianji.learning.domin.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author 金山
 * @since 2025-10-18
 */
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
@Api(tags = "我的课程相关接口")
public class LearningLessonController {
    private final ILearningLessonService lessonService;


    /**
     * 1.分页查询我的课程
     * @param pageQuery
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> pageQueryMyLessons(PageQuery pageQuery){
        return lessonService.pageQueryMyLessons(pageQuery);
    }


    /**
     * 删除退费的信息（作业）
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除退费的信息")
    public void removeLessons(@PathVariable("courseId") List<Long> courseIds){
        Long userId = UserContext.getUser();
        lessonService.removeLessons(userId,courseIds);
    }


    /**
     * 查询用户课表中指定课程状态（作业）
     */
    @GetMapping("/{courseId}")
    @ApiOperation("查询用户课表中指定课程状态")
    public LearningLessonVO getByidLessons(@PathVariable("courseId") long courseId){

        return lessonService.getByidLessons(courseId);
    }

    /**
     * 查询正在学习的课程（作业）
     */
    @GetMapping("/now")
    @ApiOperation("查询正在学习的课程")
    public LearningLessonVO getLessonsById(){

        return lessonService.getLessonsById();
    }

    /**
     * 检查课程是否有效（作业）
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("检查课程是否有效")
    public Long getCourseByCourseId(@PathVariable("courseId") Long courseId){

        return lessonService.getCourseByCourseId(courseId);
    }

    /**
     * 统计课程的学习人数（作业）
     */
    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程的学习人数")
    public Integer getCountByCourseId(@PathVariable("courseId") Long courseId){

        return lessonService.getCountByCourseId(courseId);
    }

    /**
     * 创建或修改学习计划
     * @param planDTO
     */
    @PostMapping("/plans")
    @ApiOperation("创建或修改学习计划")
    public void createPlans(@RequestBody LearningPlanDTO planDTO){
        lessonService.createPlans(planDTO);
    }

}
